<?php
/*
 * Connection Class
 * 
 * Setup a mysql connection
 * 
 * @author : Jason Meulenhoff
 * @mail : mail@kacangboi.com
 * @web : http://kacangboi.com
 * @copyright : KacangNetworks 2010
 * 
 */
class connection
{
	private $connection; // stores the connection
	
	public function __construct($host,$user,$pass,$data)
	{
		debug::message("Setting up a connection to the database string : Host : {$host} , User : {$user} , Pass : {$pass} ","INFO");
		$this->connect($host,$user,$pass,$data);
	}
	private function connect($host,$user,$pass,$data)
	{
		if($this->connection = mysql_connect($host,$user,$pass))
		{	
			debug::message("Selecting {$data} as default database","INFO");
			if(!mysql_select_db($data,$this->connection))
				throw new Exception(debug::message("Could not select your database : {$data}","ERROR","RED"));
			else
				debug::message("Created a database link with the database : {$data} , id : {$this->connection} ","INFO");
		}else{
			throw new Exception(debug::message("Could not connect to your database","ERROR","RED"));}
	}
	public function __destruct()
	{
		debug::message("Closing the database connection : {$this->connection}","INFO");
		mysql_close($this->connection);		
	}
}
?>